import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

// 学生类
class Student {
    private String id; // 学生ID
    private String name; // 学生姓名
    private String surname; // 学生姓氏

    public Student(String id, String name) {
        this.id = id;
        this.name = name;
        this.surname = name.substring(0, 1); // 假设姓名的第一个字符是姓氏
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getSurname() {
        return surname;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", surname='" + surname + '\'' +
                '}';
    }
}

// 学生管理类
class StudentManager {
    private List<Student> students; // 学生列表

    public StudentManager() {
        students = new ArrayList<>();
    }

    // 添加学生信息
    public void addStudent(Student student) {
        students.add(student);
    }

    // 按姓氏查找学生
    public void findStudentsBySurname(String surname) {
        System.out.println("查找姓氏为 '" + surname + "' 的学生信息：");
        for (Student student : students) {
            if (student.getSurname().equals(surname)) {
                System.out.println(student);
            }
        }
    }

    // 显示所有学生信息
    public void displayAllStudents() {
        System.out.println("所有学生信息：");
        for (Student student : students) {
            System.out.println(student);
        }
    }
}

// 主类
public class StudentInfoManagement {
    public static void main(String[] args) {
        StudentManager manager = new StudentManager();

        // 添加一些学生信息
        manager.addStudent(new Student("001", "张三"));
        manager.addStudent(new Student("002", "李四"));
        manager.addStudent(new Student("003", "张军"));
        manager.addStudent(new Student("004", "王五"));
        manager.addStudent(new Student("005", "张伟"));

        // 显示所有学生信息
        manager.displayAllStudents();

        // 创建一个Scanner对象用于接收用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要查找的学生姓氏：");
        String surname = scanner.nextLine();

        // 按姓氏查找学生
        manager.findStudentsBySurname(surname);

        scanner.close();
    }
}
